package org.video.common.data.model.areas.imp;

import org.video.common.data.model.areas.IArea;
import org.video.common.data.model.areas.IAreaData;
import org.video.common.data.model.properties.IProperty;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;


public abstract class AbstractArea implements IArea {

    protected IAreaData data;
    protected Collection<IProperty> properties;
    @Override
    public abstract IAreaData getData();

    @Override
    public void setData(IAreaData  _data) {
        this.data = _data;
    }

    @Override
    public IProperty getPropertyByKey(Object _key) {
        return convertToMapKey(properties).get(_key);
    }

    @Override
    public IProperty getPropertyByName(String _name) {
        return convertToMapName(properties).get(_name);
    }

    @Override
    public Collection<? extends IProperty> getAllProperties() {
        return this.properties;
    }

    @Override
    public Map<Object, ? extends IProperty> getAllPropertiesWithKey() {
        return convertToMapKey(properties);
    }

    protected Map<Object, IProperty> convertToMapName(Collection<? extends IProperty> _collection){
        Map<Object, IProperty> convetMap = new HashMap<Object, IProperty>();
        for(IProperty property: _collection){
            convetMap.put(property.getName(), property);
        }
        return convetMap;
    }

    protected Map<Object, IProperty> convertToMapKey(Collection<? extends IProperty> _collection){
        Map<Object, IProperty> convetMap = new HashMap<Object, IProperty>();
        for(IProperty property: _collection){
            convetMap.put(property.getKey(), property);
        }
        return convetMap;
    }

}
